
import constant from '@/constant/constant.js' // 常量
const inner = uni.createInnerAudioContext()

export const state = {
	version: "1.0.0",
	isLogin: '',
	mobile: '',
	memberId: '',
	openid: "",
	counter:1,
	appInfo: { // APP整体数据
		commonDataVersion: '0', // 公共数据的大版本号
		adVersion: '0', // 广告数据版本号	
		serviceVersion: '0' // 服务数据版本号
	},
	currentTabbar:0, // Tabbar当前下标
};
//缓存浏览器的数据名称
const cacheNameList = [constant.StorageName.APP_USER_INFO];
let clearTime;
export const mutations = {
	//取出缓存数据（打开APP就取出）
	setCacheData(state) {
		for (let name of cacheNameList) {
			let data;
			// #ifndef H5
			data = uni.getStorageSync(name);
			// #endif
			// #ifdef H5
			data = sessionStorage.getItem(name) || localStorage.getItem(name);
			// #endif
			if (data) {
				// #ifdef H5
				try {
					data = JSON.parse(data).data;
				} catch (e) {}
				// #endif
				state[name] = data;
			}
		}
	},
	tabbarSwitch(state,payload){
		if(payload.index === 1){
			uni.navigateTo({
				url:'/myPackageA/pages/addcharge/addcharge?type=0'
			})
			return
		}
		
		state.currentTabbar = Number(payload.index)
		uni.switchTab({
			url:`${payload.pagePath}`
		})
	},
	

};
export const actions = {
	
};
export const getters = {
	getUserMsg (state) {
		return JSON.parse(state.userInfo)
	},
}